/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package admin.informe;

/**
 *
 * @author carlo
 */

import DBMS.DataBaseManager;

import clases.Informe;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.actions.DispatchAction;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;


public class ConsultarInforme extends DispatchAction {


    /*
     * forward name="success" path=""
     */
    private final static String SUCCESS = "success";
    private final static String FAILURE = "failure";
    private static final String VERTODOS = "vertodos";

    public ActionForward one(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        return mapping.findForward(SUCCESS);
    }

    public ActionForward all(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        
        Informe informe = new Informe();
        DataBaseManager dbm = DataBaseManager.getInstance();

        ArrayList<Informe> resultadoConsulta = dbm.consultarInformes(informe);

        if (resultadoConsulta.isEmpty()) {
            informe.setMensaje("No se ha podido realizar la consulta.");
            request.setAttribute("informe", informe);
            return mapping.findForward(FAILURE);
        }

        informe.setMensajeOK("Consulta realizada con exito.");
        request.setAttribute("informes", resultadoConsulta);
        return mapping.findForward(SUCCESS);
    }
}
